/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vnetlab.ui;

import com.mxgraph.model.mxCell;
import com.mxgraph.view.mxGraph;

/**
 *
 * @author ROGERIO
 */
/**
* A graph that creates new edges from a given template edge.
*/
public class CustomGraph extends mxGraph
{
    /**
     * Holds the edge to be used as a template for inserting new edges.
     */
    protected Object edgeTemplate;

    /**
     * Custom graph that defines the alternate edge style to be used when
     * the middle control point of edges is double clicked (flipped).
     */
    public CustomGraph()
    {
            setAlternateEdgeStyle("edgeStyle=mxEdgeStyle.ElbowConnector;elbow=vertical");
    }

    /**
     * Sets the edge template to be used to inserting edges.
     */
    public void setEdgeTemplate(Object template)
    {
            edgeTemplate = template;
    }

    /**
     * Prints out some useful information about the cell in the tooltip.
     */
    public String getToolTipForCell(Object cell)
    {

        return "";
    }

    
    public Object createEdge(Object parent, String id, Object value,
                    Object source, Object target, String style)
    {
            if (edgeTemplate != null)
            {
                    mxCell edge = (mxCell) cloneCells(new Object[] { edgeTemplate })[0];
                    edge.setId(id);

                    return edge;
            }

            return super.createEdge(parent, id, value, source, target, style);
    }

}
